package cn.ubeta.ar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by liudengyong on 2017/2/14.
 */

public class BoundView extends View {

    float[] mPoints;
    Paint mPaint;

    public BoundView(Context context) {
        super(context);
    }

    public BoundView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BoundView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setBound(float[] points) {
        mPoints = points;

        if (mPaint == null) {
            mPaint = new Paint();
            mPaint.setColor(Color.GREEN);
            mPaint.setStrokeWidth(5);
        }

        invalidate();
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (mPoints != null) {
            canvas.drawLines(mPoints, mPaint);
        } else {
            canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        }
    }
}
